package com.sky.controller.backstage;

import com.sky.dto.AnnouncementsAddDTO;
import com.sky.dto.AnnouncementsUpdateDTO;
import com.sky.dto.BaclstageNoticeQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.BackstageNoticeService;
import com.sky.vo.AnnouncementsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@RestController
@RequestMapping("/backstage/notice")
@Slf4j
@Api(tags = "后台公告管理接口")
public class BackstageNoticeController {
    @Autowired
    private BackstageNoticeService backstageNoticeService;

    @PostMapping
    @ApiOperation("添加公告")
    public Result addNotice(@RequestBody AnnouncementsAddDTO announcementsAddDTO) {
        backstageNoticeService.announcementAdd(announcementsAddDTO);
        return Result.success("添加公告成功");
    }

    @GetMapping("/list")
    @ApiOperation("获取所有公告列表")
    public Result<PageResult> getAllNotice(BaclstageNoticeQueryDTO baclstageNoticeQueryDTO) {
        PageResult noticeList = backstageNoticeService.getAllNotice(baclstageNoticeQueryDTO);
        return Result.success(noticeList);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过id获取公告信息")
    public Result<AnnouncementsVO> getNoticeById(@PathVariable Integer id) {
        AnnouncementsVO announcementsVO = backstageNoticeService.getNoticeById(id);
        return Result.success(announcementsVO);
    }

    @PutMapping
    @ApiOperation("修改公告信息")
    public Result updateNoticeById(@RequestBody AnnouncementsUpdateDTO announcementsUpdateDTO) {
        backstageNoticeService.updateAnnouncement(announcementsUpdateDTO);
        return Result.success("公告修改成功");
    }

    @DeleteMapping("/user/delete")
    @ApiOperation("删除公告")
    public Result deleteUser(@RequestBody List<Integer> ids) {
        backstageNoticeService.deleteAnnouncement(ids);
        return Result.success("删除成功");
    }
}
